package com.project.easy.common.framework.web.controller;


import com.project.easy.common.framework.web.entity.FrameworkSysParam;
import com.project.easy.common.framework.web.entity.dto.PageSysParamReq;
import com.project.easy.common.framework.web.entity.dto.SysParamDto;
import com.project.easy.common.framework.web.entity.dto.SysParamUpdateDto;
import com.project.easy.common.framework.web.entity.dto.SysParamVerifyCodeReq;
import com.project.easy.common.log.annotation.Logging;
import  com.project.easy.common.util.collection.CollectionUtil;
import  com.project.easy.common.util.constants.VersionConstant;
import  com.project.easy.common.util.dto.IdApiContextParam;
import  com.project.easy.common.util.dto.OneLongApiContextParam;
import  com.project.easy.common.util.dto.PageResDto;
import  com.project.easy.common.util.dto.R;
import com.project.easy.common.framework.web.annotation.ApiValidator;
import com.project.easy.common.framework.web.service.IFrameworkSysParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * <p>
 * 系统参数表 前端控制器
 * </p>
 *
 * @author GreatorMan.cool
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/api/" + VersionConstant.ONE + "/zysoft/sysParam")
public class FrameworkSysParamController extends BaseController {

    @Autowired
    private IFrameworkSysParamService frameworkSysParamService;
    /**
     * 新增
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/add")
    @Logging
    @ApiValidator
    public R<Long> add(@RequestBody SysParamDto sysParamDto) {
        return R.success(frameworkSysParamService.add(sysParamDto));
    }
    /**
     * 修改
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/udpate")
    @Logging
    @ApiValidator
    public R<Boolean> udpate(@RequestBody SysParamUpdateDto sysParamDto) {
        return R.success(frameworkSysParamService.updateObject(sysParamDto));
    }
    /**
     * 列表
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/pageList")
    @Logging
    @ApiValidator
    public R<PageResDto<FrameworkSysParam>> pageList(@RequestBody PageSysParamReq sysParamDto) {
        return R.success(frameworkSysParamService.pageList(sysParamDto));
    }
    /**
     * 验证编码
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/verifyCode")
    @Logging
    @ApiValidator
    public R<Boolean> verifyCode(@RequestBody SysParamVerifyCodeReq sysParamDto) {
        return R.success(frameworkSysParamService.verifyCode(sysParamDto));
    }
    /**
     * 删除
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/del")
    @Logging
    @ApiValidator
    public R<Boolean> del(@RequestBody IdApiContextParam sysParamDto) {
        return R.success(this.del(frameworkSysParamService, v -> v::setHasDel,
                CollectionUtil.parseIds(sysParamDto.getIds())));
    }
    /**
     * 禁用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/disAble")
    @Logging
    @ApiValidator
    public R<Boolean> disAble(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkSysParamService.disAble(oneApiContextParam.getKey()));
    }
    /**
     * 启用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/able")
    @Logging
    @ApiValidator
    public R<Boolean> able(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkSysParamService.able(oneApiContextParam.getKey()));
    }
}
